/*
 * Copyright 2012 The University of Auckland
 */

#include "modules/mod_sampler2d.frag"

uniform sampler2D colourTex_;
uniform sampler2D LICTex_;
uniform TextureParameters texParams_;



vec4 getColour(const float m) {

	// HOT METAL COLOURCODING
    const int colorTableSize = 4;
    vec3 colorTable[colorTableSize];
    colorTable[0] = vec3(0.0, 0.0, 0.0);    // black
    colorTable[1] = vec3(1.0, 0.0, 0.0);    // red
    colorTable[2] = vec3(1.0, 1.0, 0.0);    // yellow
    colorTable[3] = vec3(1.0, 1.0, 1.0);    // white

    float numColors = float(colorTableSize - 1);
    float v = clamp(m * numColors, 0.0, numColors);
    ivec2 limits = clamp(ivec2(int(v), int(ceil(v))), 0, colorTableSize);
    vec3 color = mix(colorTable[limits.x], colorTable[limits.y], fract(v));
    return vec4(color, 1.0);
}



void main() {
	float lic_intensity = textureLookup2Dscreen(LICTex_, texParams_, gl_FragCoord.xy).x;
	float col_intensity = textureLookup2Dscreen(colourTex_, texParams_, gl_FragCoord.xy).x;
	
	vec4 colour = getColour(col_intensity);
	
	FragData0 = colour;
	
	// TODO
	// 1. mix with LIC texture - perhaps invert LIC value if scalar_value is 
	//	  higher than 0.5, or smt..
	// 2. determine relative importance of both fields at this pixel (perhaps
	//	  we need the complete flowfield for that) and mix accordingly.
}
